# class MyClass:
#       i = 12345
#       def f(self):
#             return 'hello object'
      
# x = MyClass()

# print("MyClass 类的属性i为：",x.i)
# print("MyClass 类的方法f输出为：",x.f())

# class MyClass:
#       def __init__(self):
#             print("构造方法执行！")

# x = MyClass()
# class Complex:
#       def __init__(self,realpart,imagpart):
#             self.r = realpart
#             self.i = imagpart

# x = Complex(3.0,-4.5)

# print(x.r,x.i)

# class Test:
#       def prt(self):
#             print(self)
#             print(self.__class__)

# t = Test()
# t.prt()

# class MyClass:
#       def __init__(self,value):
#             self.value = value

#       def display_value(self):
#             print(self.value)

# obj = MyClass(42)

# obj.display_value()

# class People:
#       # 定义基本属性
#       name = ''
#       age = 0
#       # 定义私有属性，私有属性在类外部无法直接访问
#       __weight__ = 0
#       # 构造方法
#       def __init__(self,n,a,w):
#             self.name = n
#             self.age = a
#             self.__weight__ = w
#       # 定义方法
#       def speak(self):
#             print("%s 说：我 %d 岁。" %(self.name,self.age))

# class Student(People):
#       grade = ''
#       def __init__(self,n,a,w,g):
#             People.__init__(self,n,a,w)
#             self.grade = g

#       #重写父类的方法
#       def speak(self):
#             print("%s 说：我 %d 岁了，我在读 %d 年级。" %(self.name,self.age,self.grade))

# class Speaker():
#       topic = ''
#       name = ''

#       def __init__(self,n,t):
#             self.name = n
#             self.topic = t

#       def speak(self):
#             print("我叫 %s,我是一个演说家，我演讲的主题是：%s。" %(self.name,self.topic))

# # 多继承
# class Sample(Speaker,Student):
#       a = ''
#       def __init__(self,n,a,w,g,t):
#             Student.__init__(self,n,a,w,g)
#             Speaker.__init__(self,n,t)

# p = Sample('刘备',30,80,'博士','三国')
# p.speak()

class Site:
      def __init__(self,name,url):
            self.name = name #公共属性，可被继承
            self.__url = url #私有属性

      def who(self):
            print('name :',self.name)
            print('url:',self.__url)

      def __foo(self): #私有方法
            print('这是私有方法')

      def foo(self):
            print('这是公共方法')
            # 调用私有方法，内部可以调用
            self.__foo()

x = Site('百度网站','www.baidu.com')
x.who()
x.foo()
# x.__foo()方法会报错，外部不可调用私有方法